package com.ganzi.manager.controller;

import com.ganzi.manager.activiti.request.PublishRequest;
import com.ganzi.manager.activiti.request.SaveModelRequest;
import com.ganzi.manager.activiti.service.ModelerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 自定义流程
 */
@RestController
@RequestMapping("/modeler")
public class ModelerController {

    private static final Logger logger = LoggerFactory.getLogger(ModelerController.class);

    @Autowired
    private ModelerService modelerService;


    /**
     * 获取所有model
     * */
	@GetMapping("list")
	public Object list() {
        return modelerService.getModelList();
	}
    
    /**
     * 保存模型
     */
    @PostMapping("/saveModel")
    public Object saveModel(@RequestBody SaveModelRequest saveModelRequest){
		return modelerService.saveModel(saveModelRequest,false);
    }

    /**
     * 编辑模型
     */
    @PostMapping("/editModel")
    public Object editModel(@RequestBody PublishRequest publishRequest){
		return modelerService.editModel(publishRequest,false);
    }

    /**
     * 验证模型格式模型
     */
    @PostMapping("/cheakModel")
    public Object cheakModel(@RequestBody PublishRequest publishRequest){
		return modelerService.cheakModel(publishRequest,false);
    }
    
    /**
     * 发布流程
     */
    @PostMapping("/publish")
    public Object publish(@RequestBody PublishRequest publishRequest){
		return modelerService.publish(publishRequest,false);
    }
    
    /**
     * 撤销发布的流程
     * @return
     */
	@PostMapping("/revokePublish")
	public Object revokePublish(@RequestBody PublishRequest publishModelerRequest){
		return modelerService.revokePublish(publishModelerRequest);
	}
    
    /**
     * 删除模型及流程实例及运行的流程
     * @return
     */
	@PostMapping("/delete")
	public Object deleteProcessInstance(@RequestBody PublishRequest publishModelerRequest){
		return modelerService.deleteModel(publishModelerRequest);
	}
}
